#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 2e5 + 10;
bool d[N];


bool check(int n, int k){
    for(int i = 1; i <= n / 2; i ++){
        if(i % 2 == 0){
            d[i] = false;
        }else{
            d[i] = true;
        }
    }

    for(int i = 1; i <= n / 2; i ++){
        if(d[i] && (k + i * 2) % 4){
            return false;
        }
    }

    return true;
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);
    int n, k;
    while(T--){
        memset(d, 0, sizeof d);
        scanf("%d%d", &n, &k);
        if(k % 2 == 0){
            if(check(n, k)){
                printf("YES\n");
                int p = 1;
                for(int i = 1; i <= n / 2; i ++){
                    if(!d[i]){
                        printf("%d %d\n", p, i * 2);
                    }else{
                        printf("%d %d\n", i * 2, p);
                    }
                    p += 2;
                }
            }else{
                printf("NO\n");
            }
            
        }else{
            printf("YES\n");
            for(int i = 1; i <= n; i += 2){
                printf("%d %d\n", i, i + 1);
            }
        }
    }

    return 0;
}